class Student{
  int id;
  String name;

  Student(this.id, this.name);

  // 重写==实现对象判断
  @override
  bool operator == (other){
    // 检测类型是否匹配
    if(other is! Student){
      return false;
    }

    // 比较属性是否相同
    final Student student = other;
    return id == student.id;
  }

  @override
  int get hashCode{
    print("调用 hashCode");
    return name.length;
  }

  @override
  String toString() {
    return 'Student:{id:$id, name:$name}';
  }

}



void main(){
  List list = List();
  Student z1 = Student(1, '张三');
  list.add(z1);
  list.add(Student(2, '李四'));
  list.add(Student(3, '王五'));
  print(list);

  Student zhangsan = Student(1, 'zhangsan');
  if(list.contains(zhangsan)){
    print('$zhangsan 已存在集合中');
  }else{
    print('$zhangsan 不存集合中');
  }


  if(z1 == zhangsan){
    print("相等的");
  }

}